<template>
	<el-cascader v-bind="$attrs"
				 :size="size"
				 :options="cascadeOptions"
				 :props="cascadeProps"
				 :style="width?'width:'+width+'px;':'width:100%;'"
				 :show-all-levels="false"
				 :placeholder="placeholder?placeholder:$t('common.please_choose')"
				 filterable
				 clearable>
	</el-cascader>
</template>
<script>
export default {
	name: "exCascader",
	components: {},
	props: {
		keyProp: {type: String, default: null},
		checkStrictly: {type: Boolean, default: true},
		placeholder: {type: String, default: null},
		size: {type: String, default: "default"},//"" | "default" | "small" | "large"
		width: {type: Number, default: null},
		dictCode: {type: String, default: null},
		params: {type: Object, default: {}},
		multiple: {type: Boolean, default: false}
	},
	data() {
		return {
			cascadeOptions: [],
			cascadeProps: {
				value: this.keyProp || 'id',
				label: 'label',
				checkStrictly: this.checkStrictly,
				expandTrigger: 'click',//hover
				multiple: this.multiple,
				emitPath: false,
				lazy: false,
				lazyLoad(node, resolve) {
					resolve(node.children);
				}
			},
		};
	},
	async mounted() {
		let params = {parentLevelCode: "0000000"};
		this.cascadeOptions = await this.$cache.tree.options(this.dictCode, Object.assign(params, this.params));
		this.addDisabled(this.cascadeOptions);
	},
	methods: {
		addDisabled(datas){
			datas.forEach(item=>{
				item.disabled = item.isEnabled !== '1';
				if(item.children){
					this.addDisabled(item.children);
				}
			})
		},
	}
}
</script>
